import pandas as pd
import seaborn as sn
import matplotlib.pyplot as plt
import numpy as np

params = {'legend.fontsize':'x-large',
          'figure.figsize':(30,10),
          'axes.labelsize':'x-large',
          'xtick.labelsize':'x-large',
          'ytick.labelsize':'x-large',
          }
sn.set_style('whitegrid')
sn.set_context('talk')

plt.rcParams.update(params)
pd.options.display.max_colwidth = 600

from IPython.display import display, HTML
day_filename = r'E:\\images\day.csv'
train = pd.read_csv(day_filename)
train.head()

train.info()

#数据探索
train.describe()
categorical_features = ['season','mnth','weather','weekday']
for col in categorical_features:
    print('\n%s属性的不同取值和出现的次数'%col)
    print(train[col].value_counts())
    train[col] = train[col].astype('object')

#数值分布特征
numeriacal_features = ['temp','atemp','hum','windspeed']
train[numeriacal_features].hist()

#特征与目标之间的关系
#每年骑行量的分布
sn.violinplot(data=train[['yr','cnt',]],x='yr', y='cnt')
#一年中每一天的骑行量
import  datetime
train['date'] = pd.to_datetime(train['dteday'])
train['dayofyear'] = train["date"].dt.dayofyear
fig,ax = plt.subplots()
sn.pointplot(data=train[['dayofyear','cnt','yr']],x='dayofyear',y='cnt',hue='yr',ax=ax)
ax.set(tiele = 'dayky distributetion of count')

#季节与骑行量的关系
sn.violinplot(data=train[['season','cnt']],x = 'season',y='cnt')
#季节骑行量的分布不同，骑行量集中程度
fig,ax = plt.subplots()
sn.barplot(data=train[['season','cnt']],x='season',y='cnt')
ax.set(title='seasonly distribution of counts')

#月份与骑行量的关系
fig,ax = plt.subplots()
sn.barplot(data=train[['mnth','cnt']],x='mnth',y='cnt')
ax.set(title='monthly distribution of counts')

#天气与骑行量的关系
fig,ax = plt.subplots()
sn.barplot(data=train[['weather','cnt']],x='weather',y='cnt')
ax.set(title='weathersit distribution of counts')

#工作日与节假日的分布
fig,(ax1,ax2) = plt.subplots()
sn.barplot(data=train,x='holiday',y='cnt',ax=ax1)
sn.barplot(data=train,x='workingday',y='cnt',ax=ax2)

#数值性特征与y之间的相关性
corrMatt = train[['temp','atemp',
                  'hum','windspeed',
                  'casual','registered',
                  'cnt']].corr()
mask = np.array(corrMatt)
mask[np.tril_indices_from(mask)] = False
xn.heatmap(corrMatt,mask =mask,vmax=.8,square=True,annot=True)

